unit codemyth.workflow;

interface

uses TypInfo, codemyth.utils, Types;

type

    TWorkFlow = class
    private
        FFlowEnum: PTypeInfo;
        FCount: integer;
        FFlowCaptions: TStringDynArray;
        function GetFlow( const order: integer ): string;
        function GetFlowCaption( const order: integer ): string;
    function GetFlowIndex(const Caption: string): integer;
    public
        constructor Create( flowEnum: PTypeInfo; FlowCaptions: TStringDynArray
            );
        //TStringDynArray
    public
        property Count: integer read FCount;
        property Flows [ const order: integer ]: string read GetFlow;
        property FlowCaptions [ const order: integer ]: string read
        GetFlowCaption;
        property FlowIndex[const Caption:string]:integer read GetFlowIndex;
        function EnumValue( const Flow: string ): integer;
    end;

implementation

{ TWorkFlow }

constructor TWorkFlow.Create( flowEnum: PTypeInfo; FlowCaptions: TStringDynArray
    );
begin
    Check( flowEnum^.Kind = tkEnumeration, 'not be a Enumeration Type.' );
    FFlowEnum := flowEnum;
    FCount := GetTypeData( FFlowEnum ).MaxValue - GetTypeData( FFlowEnum
        ).MinValue + 1;
    FFlowCaptions := FlowCaptions;
end;

function TWorkFlow.EnumValue( const Flow: string ): integer;
begin
    result := GetEnumValue( FFlowEnum, Flow );
end;

function TWorkFlow.GetFlow( const order: integer ): string;
begin
    Result := GetEnumName( FFlowEnum, order );
end;

function TWorkFlow.GetFlowCaption( const order: integer ): string;
begin
    result := FFlowCaptions [ Order ];
end;

function TWorkFlow.GetFlowIndex(const Caption: string): integer;
var
    i:Integer;
begin
    for i := 0 to Length(FFlowCaptions)-1 do
    begin
        if FFlowCaptions[i] = Caption then
        begin
            result:= i;
            break;
        end;
    end;
end;

end.

